
* prepare datasets 1980-2000
* This will be used to calculate workers' average wages, average censoring indicators, and their imputed education

version 14.2
clear all
macro drop _all
set more off


foreach y of numlist 1980/2000{
di "`y'"
use "data\orig/clean`y'.dta", clear
gen year=`y'
do "do-files\data_management/cr_prepare_variables_genmeans_ado.do"
keep vsnr year lw cens 
sum
compress
save "base`y'.dta", replace
}

use "base1980.dta", clear
foreach y of numlist 1981/2000{
append using "base`y'.dta"
}

sort vsnr year
foreach X of varlist lw cens{
by vsnr: egen i`X'=mean(`X')
}

by vsnr: gen nobs=_N

bys vsnr: keep if _n==1
keep vsnr ilw icens nobs

sum
tab nobs

compress
save "data\pmeans1980_2000.dta", replace


foreach y of numlist 1980/2000{
erase "base`y'.dta"
}

dir *.dta

clear all

exit
